package com.wjk.kylin.mall.product.kafka.datasync;

import com.alibaba.fastjson.JSONObject;
import com.wjk.kylin.mall.product.beanmapper.ProductEntityMapper;
import com.wjk.kylin.mall.product.entity.es.MallProductESBean;
import com.wjk.kylin.mall.product.entity.es.ProductESBean;
import com.wjk.kylin.mall.product.enums.ProductDataSyncEsTableEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;


/**
 * @description: 主表数据
 * @author: wangjinkui
 * @create: 2022-07-18
 **/
@Slf4j
@Component
public class MallProductDataSyncExecutor extends ProductDataSyncExecutor {
    @Override
    public ProductDataSyncEsTableEnum getTableEnum() {
        return ProductDataSyncEsTableEnum.MALL_PRODUCT;
    }

    @Override
    public void insertOrUpdateEs(JSONObject fieldsJson, Map<Long, ProductESBean> isExistEsMap, Long productId) {
        ProductESBean esBean = isExistEsMap.get(productId);
        if (esBean == null) {
            esBean = JSONObject.toJavaObject(fieldsJson, ProductESBean.class);
            isExistEsMap.put(productId, esBean);
            esBean.setProductId(productId);
        } else {
            MallProductESBean mallProductESBean = JSONObject.toJavaObject(fieldsJson, MallProductESBean.class);
            ProductEntityMapper.INSTANCE.mEs2ESBean(mallProductESBean, esBean);
        }
    }

    @Override
    public void deleteEs(JSONObject fieldsJson, Map<Long, ProductESBean> isExistEsMap, List<String> pkNames, Long productId) {
        //TODO 不需要处理
    }
}
